package com.example.wangshuo.zyfypt_205ws.model;

import com.example.wangshuo.zyfypt_205ws.bean.LoginBean;
import com.example.wangshuo.zyfypt_205ws.iface.LoginListener;
import com.example.wangshuo.zyfypt_205ws.iface.Loginiface;
import com.example.wangshuo.zyfypt_205ws.iface.RegisterListener;
import com.example.wangshuo.zyfypt_205ws.iface.Registeriface;
import com.example.wangshuo.zyfypt_205ws.service.LoginService;
import com.example.wangshuo.zyfypt_205ws.service.RegisterService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
/**
 * Created by wangshuo on 2017/5/1.
 */
public class LoginModel implements Loginiface {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";

    public LoginModel(){
        //实例化retrofit
        retrofit=new Retrofit.Builder().baseUrl(BASEURL).addConverterFactory(GsonConverterFactory.create()).build();

    }
    @Override
    public void getResultList(String username, String password, final LoginListener listener) {
        LoginService loginService=retrofit.create(LoginService.class);
        Call<LoginBean> call=loginService.login(username,password);
        call.enqueue(new Callback<LoginBean>() {
            @Override
            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
                listener.onResponse( response.body());
            }
            @Override
            public void onFailure(Call<LoginBean> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
